package com.lht.testDemo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import org.junit.Test;

import java.util.List;

/**
 * @author Eric
 * @version 1.0
 * @date 2019-07-19
 */
public class FastJsonTest {

    @Test
    public  void testStringToGenericity(){
        A<String> a=new A<>();
        a.setE("hello");
        String text=JSON.toJSONString(a);

        toE(String.class,text);
    }


    public <E> A<E> toE(E e,String text){
        A<E> ea = JSON.parseObject(text, new TypeReference<A<E>>(){});

        return ea;
    }

    public static class A<E>{
        private E e;

        public E getE() {
            return e;
        }

        public void setE(E e) {
            this.e = e;
        }
    }
}
